tools/ocaml/xenstored: Fix path length validation
authorEdwin Török <edvin.torok@citrix.com>
Tue, 15 Dec 2020 11:29:24 +0000 (12:29 +0100)
committerHans van Kranenburg <hans@knorrie.org>
Tue, 15 Dec 2020 11:29:24 +0000 (12:29 +0100)
commite2ffddc85f9aedcd42073ffb28b7f753cdc7a5a1
tree3c5e5dca04cb095c9513da2875d891d69eed4ca9
parent512902a8d026d6a2d9f0ebbbab2a35178b137f9b
tools/ocaml/xenstored: Fix path length validation

Currently, oxenstored checks the length of paths against 1024, then
prepends "/local/domain/$DOMID/" to relative paths.  This allows a domU
to create paths which can't subsequently be read by anyone, even dom0.
This also interferes with listing directories, etc.

Define a new oxenstored.conf entry: quota-path-max, defaulting to 1024
as before.  For paths that begin with "/local/domain/$DOMID/" check the
relative path length against this quota. For all other paths check the
entire path length.

This ensures that if the domid changes (and thus the length of a prefix
changes) a path that used to be valid stays valid (e.g. after a
live-migration).  It also ensures that regardless how the client tries
to access a path (domid-relative or absolute) it will get consistent
results, since the limit is always applied on the final canonicalized
path.

Delete the unused Domain.get_path to avoid it being confused with
Connection.get_path (which differs by a trailing slash only).

Rewrite Util.path_validate to apply the appropriate length restriction
based on whether the path is relative or not.  Remove the check for
connection_path being absolute, because it is not guest controlled data.

This is part of XSA-323.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/ocaml/libs/xb/partial.ml
tools/ocaml/libs/xb/partial.mli
tools/ocaml/xenstored/define.ml
tools/ocaml/xenstored/domain.ml
tools/ocaml/xenstored/oxenstored.conf.in
tools/ocaml/xenstored/utils.ml
tools/ocaml/xenstored/xenstored.ml